<?php
class Searchlist extends CI_Model {

	function __construct()
	{
		parent::__construct();

	}

	function get_search_list()
	{
		//get from DB
		$rs = $this->process_data->get_paper();
		return $this->generate_search_list_view($rs);
	}
	
	function get_search_listForUser($userId)
	{
		//get from DB
		$rs = $this->process_data->get_paperByUserId($userId);
		return $this->generate_search_list_view($rs);
	}
	
	function get_search_list_subject($subjetName)
	{
		//get from DB
		$subjetName;
		//$this->db->like('name', $subjetName); 
		$query = $this->db->query('SELECT * FROM tbl_paper where subject_ref in (SELECT id FROM det_subjects where name like \'%'.$subjetName.'%\')');
		$rs = $query->result_array();
		return $this->generate_search_list_view($rs);
	}

	function generate_search_list_view($rs)
	{
		$list = array();
		for($i=0; $i<count($rs);$i++)
		{
			$list[$i]['paperImageThumb'] = $rs[$i]['paper_filename'];
			$list[$i]['authorDetails'] = $this->process_data->usersFullDetails_Id($rs[$i]['posted_by']);
			$list[$i]['paperTitle'] = $rs[$i]['name'];
			$list[$i]['paperAbstract'] = $rs[$i]['abstract'];
			$list[$i]['pubDate'] = $rs[$i]['pub_date'];
			$list[$i]['isbn'] = $rs[$i]['isbn'];
			$list[$i]['pages'] = $rs[$i]['pages'];
			$list[$i]['admin_approved'] = $rs[$i]['admin_approved'];
			
		}
		return $list;
	}
	
	function get_main_subject_id($subjetName){
		$query = $this->db->query('SELECT * FROM det_subjects where name like \'%'.$subjetName.'%\'');
		return $query->result_array();
	}

}

?>